//
// Created by Tan Ke on 2024/1/1.
//

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>

bool buddyStrings(char* s, char* goal)
{
    char s_1, s_2;
    char goal_1, goal_2;
    int diff_cnt = 0;
    int charCnt[26] = {0};

    for (int i = 0; i < 26; i ++) {
        charCnt[i] = 0;
    }

    if (strlen(s) != strlen(goal)) {
        return false;
    }

    for (int i = 0; i < strlen(s); i ++) {
        charCnt[s[i] - 'a'] += 1;

        if (s[i] == goal[i]) {
            continue;
        }

        if (diff_cnt == 0) {
            s_1 = s[i];
            goal_1 = goal[i];
            diff_cnt += 1;
        } else if (diff_cnt == 1) {
            s_2 = s[i];
            goal_2 = goal[i];
            diff_cnt += 1;
        } else {
            return false;
        }
    }

    if (diff_cnt == 0) {
        for (int i = 0; i < 26; i ++) {
            if (charCnt[i] > 1) {
                return true;
            }
        }
        return false;
    }
    if (diff_cnt != 2) {
        return false;
    }

    if (s_1 == goal_2 && s_2 == goal_1) {
        return true;
    }
    return false;
}

int main(void)
{
    return 0;
}